package bizapi.sinosoft.com.provider.price;

import bizapi.sinosoft.com.provider.CommonResponse;
import com.weibo.api.motan.config.springsupport.annotation.MotanReferer;
import jd.api.request.product.SkuEntity;
import jd.api.service.product.JdProductApi;
import jd.api.vo.product.PriceVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import utils.Lang;

import java.util.List;

/**
 * Created by admin on 2017/2/9.
 */
@RestController
@RequestMapping("api/price")
public class ProductPriceCheckController {
    @MotanReferer
    JdProductApi jdProductApi;

    @RequestMapping(value = "getSellPrice", method = RequestMethod.POST)
    public CommonResponse<List<PriceVO>> getSellPrice(String sku) {
        CommonResponse<List<PriceVO>> commonResponse = new CommonResponse();
        try {
            String[] skuArray = sku.split(",");
            SkuEntity skuEntity = new SkuEntity();
            for (int i = 0; i < skuArray.length; i++) {
                skuEntity.setSku(skuArray[i]);
            }
            List<PriceVO> priceVOS = jdProductApi.getPrice(skuEntity);
            if(Lang.isEmpty(priceVOS)){
              commonResponse.setSuccess(false);
            }
            else {
                commonResponse.setResult(priceVOS);
                commonResponse.setSuccess(true);
            }
            return commonResponse;
        } catch (Exception e) {
            commonResponse.setResultMessage(e.getMessage());
            commonResponse.setSuccess(false);
            return commonResponse;
        }
    }
}
